package com.lscl.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class AckListener {

    @RabbitListener(queues = "test_queue_confirm")
    public void test_queue_confirm(Message message, Channel channel) throws Exception {

//        try {
            //1.获取消息
            System.out.println(new String(message.getBody()));

            //2. 处理业务逻辑
            System.out.println("处理业务逻辑...");

            int i = 1 / 0;

            // 签收消息
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
//        } catch (Exception e) {
//            e.printStackTrace();
//
//            // 拒绝签收
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(), true, true);
//        }
    }
}

